using System;
namespace CGF
{
    public partial class PanelEditLanguage : UIComponentBase, IAwake<UILayer, bool>, IDestroy
    {
        public static event Action onLanguageChange;
        
        public static void Open()
        {
            UIManagerComponent.instance.OpenUI<PanelEditLanguage>(UILayer.Normal, RootComponent.instance, false);
        }

        public static void Close()
        {
            UIManagerComponent.instance.CloseUI<PanelEditLanguage>();
        }

        public async void Awake(UILayer layer, bool isFloat)
        {
            await SpawnPrefab("Prefabs/GameUI/PanelEditLanguage", layer, isFloat);
			BindProperties(transform);
            
            BtnBack.SetClick(Close);
            
            //巴西包不要中文
            if (CGFConfig.Instance.ReleaseArea == EArea.Brazil && CGFConfig.Instance.ResServerType == EResServerType.FormalServer)
            {
                Content.switchs[0].gameObject.SetActive(false);
            }

            Content.CurrIndex = (int)I18N.CurrLanguage;

            BtnConfirm.SetClick(() =>
            {
                I18N.CurrLanguage = (ELanguage)Content.CurrIndex;
                onLanguageChange?.Invoke();
                Close();
            });
        }

        public override void OnDestroy()
        {
            base.OnDestroy();
        }

    }
}
